import App from './App'

// #ifndef VUE3
import Vue from 'vue'
import './uni.promisify.adaptor'
Vue.config.productionTip = false

import {
  isBoj
} from './common/util.js'
import uView from "uview-ui";
Vue.use(uView);

uni.getSystemInfo({
  success: (res) => {
    // 根据 屏幕高度 进行判断
    let screenHeight = res.screenHeight
    let bottom = res.safeArea.bottom
    Vue.prototype.windowHeight = res.windowHeight // 屏幕高度
    Vue.prototype.isFullSucreen = screenHeight !== bottom // 当前设备是否需要适配 true为需要 底部留 30px 距离
    Vue.prototype.statusBarHeight = res.statusBarHeight // 状态栏高度
  }
})

// 跳转bar
Vue.prototype.jumpTab = function(url) {
  uni.switchTab({
    url
  })
}

// 跳转非bar
Vue.prototype.jumpTo = function(url, params) {
  if (isBoj(params)) {
    url += '?'
    for (const key in params) {
      url += `${key}=${params[key]}&`
    }
    url = url.substr(0, url.length - 1)
  }
  uni.navigateTo({
    url
  })
}

// 关闭所有页面
Vue.prototype.reLaunch = function(url, params) {
  if (isBoj(params)) {
    url += '?'
    for (const key in params) {
      url += `${key}=${params[key]}&`
    }
    url = url.substr(0, url.length - 1)
  }
  uni.reLaunch({
    url
  })
}

// 关闭当前页面
Vue.prototype.redirectTo = function(url, params) {
  if (isBoj(params)) {
    url += '?'
    for (const key in params) {
      url += `${key}=${params[key]}&`
    }
    url = url.substr(0, url.length - 1)
  }
  uni.redirectTo({
    url
  })
}

// 返回上一页
Vue.prototype.goBack = function(num = 1) {
  uni.navigateBack({
    delta: num
  })
}

App.mpType = 'app'
const app = new Vue({
  ...App
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif